clear; clc; close all;

% 参数设置
a = 0.02;
b = 2.6;
c = 1.1;
d = 0.001;

N = 50000;          % 迭代总步数
discard = 1000;     % 丢弃前 discard 步暂态

% 初始条件 (0.1, 0.2 ± k*pi), k = 0, ±2, ±4, ±6
initConds = [
    0.1, 0.2 - 6*pi;
    0.1, 0.2 - 4*pi;
    0.1, 0.2 - 2*pi;
    0.1, 0.2;
    0.1, 0.2 + 2*pi;
    0.1, 0.2 + 4*pi;
    0.1, 0.2 + 6*pi
];

colors = {
    [176, 224, 176]/255;  % 浅柔绿  (Pastel Green)
    [209, 181, 218]/255;  % 浅柔紫  (Pastel Purple)
    [255, 195, 220]/255;  % 粉柔   (Pastel Pink)
    [166, 221, 221]/255;  % 浅柔青  (Pastel Teal)
    [255, 229, 180]/255;  % 浅柔橙  (Pastel Orange)
    [220, 220, 220]/255;  % 浅灰   (Light Grey)
    [200, 240, 200]/255;  % 浅青绿 (Extra Light Green)
};


% ============ 3. 创建图形并绘制 ============
figure('Color','w'); hold on; box on;

for i = 1:size(initConds,1)
    x = zeros(N,1);
    y = zeros(N,1);
    
    % 设置初始值
    x(1) = initConds(i,1);
    y(1) = initConds(i,2);
    
    % 迭代 MNFM1 映射
    for k = 1:N-1
        [x(k+1), y(k+1)] = f1(x(k), y(k), a, b, c, d);
    end
    
    % 绘制丢弃暂态后的轨迹
    plot(x(discard+1:end), y(discard+1:end), '.', ...
        'Color', colors{i}, 'MarkerSize', 2);
end

xlabel('x', 'FontSize',12);
ylabel('y', 'FontSize',12);
title('Coexisting Chaos for Various (x(0), y(0))', 'FontSize',14);

legendStrings = {...
    '(0.1, 0.2 - 6\pi)',...
    '(0.1, 0.2 - 4\pi)',...
    '(0.1, 0.2 - 2\pi)',...
    '(0.1, 0.2)',...
    '(0.1, 0.2 + 2\pi)',...
    '(0.1, 0.2 + 4\pi)',...
    '(0.1, 0.2 + 6\pi)'
};
legend(legendStrings, 'Location','best', 'Interpreter','tex');

axis tight;
% exportgraphics(gcf, 'fig5_coexisting_chaos.png', 'Resolution',300);
